﻿<UserControl x:Class="IQToolkitCodeGen.View.CustomSchemaSqlView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d">
    <UserControl.Resources>
        <Style TargetType="TextBox">
            <Setter Property="MaxHeight"
                    Value="300" />
            <Setter Property="MaxWidth"
                    Value="500" />
            <Setter Property="MinHeight"
                    Value="300" />
            <Setter Property="MinWidth"
                    Value="500" />
            <Setter Property="AcceptsReturn"
                    Value="True" />
            <Setter Property="AcceptsTab"
                    Value="True" />
        </Style>
        <Style TargetType="Button">
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="MinWidth"
                    Value="50" />
        </Style>
    </UserControl.Resources>
    <Grid DataContext="{Binding CustomSchemaSqlViewModel}"
          Background="{StaticResource PanelBodyBackgroundColorBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <TabControl Margin="5"
                    Background="{StaticResource PanelBodyBackgroundColorBrush}">
            <TabItem Header="Table Schema">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Label Content="Custom Query"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <TextBox Grid.Row="1"
                             Text="{Binding TableSchemaSql}"
                             TextWrapping="Wrap" />
                    <Label Content="Expected Results Format"
                           Grid.Row="2"
                           Grid.ColumnSpan="3"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <StackPanel Grid.Row="3">
                        <DataGrid ItemsSource="{Binding TableSchemaInfo}"
                                  AutoGenerateColumns="False"
                                  CanUserReorderColumns="False"
                                  CanUserResizeColumns="False"
                                  CanUserResizeRows="False"
                                  CanUserSortColumns="False"
                                  Focusable="False"
                                  IsReadOnly="True">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Column Name"
                                                    Binding="{Binding ColumnName}" />
                                <DataGridTextColumn Header="Type"
                                                    Binding="{Binding Type}" />
                            </DataGrid.Columns>
                        </DataGrid>
                        <TextBlock Foreground="{StaticResource DefaultTextColor}">* Set Table_Type to "View" to indicate that it is a view.</TextBlock>
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="Column Schema">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Label Content="Custom Query"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <TextBox Grid.Row="1"
                             Text="{Binding ColumnSchemaSql}"
                             TextWrapping="Wrap" />
                    <Label Content="Expected Results Format"
                           Grid.Row="2"
                           Grid.ColumnSpan="3"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <StackPanel Grid.Row="3">
                        <DataGrid ItemsSource="{Binding ColumnSchemaInfo}"
                                  AutoGenerateColumns="False"
                                  CanUserReorderColumns="False"
                                  CanUserResizeColumns="False"
                                  CanUserResizeRows="False"
                                  CanUserSortColumns="False"
                                  Focusable="False"
                                  IsReadOnly="True">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Column Name"
                                                    Binding="{Binding ColumnName}" />
                                <DataGridTextColumn Header="Type"
                                                    Binding="{Binding Type}" />
                            </DataGrid.Columns>
                        </DataGrid>
                        <TextBlock Foreground="{StaticResource DefaultTextColor}"
                                   Text="* The query needs to filter by table name.  Use {{tableName}} as the replaceable token." />
                        <TextBlock Foreground="{StaticResource DefaultTextColor}">* The Data_Type field needs to match a value from the TypeName</TextBlock>
                        <TextBlock Foreground="{StaticResource DefaultTextColor}"
                                   Margin="10 0 0 0">field in the DataTypes schema.</TextBlock>
                        <TextBlock Foreground="{StaticResource DefaultTextColor}"
                                   Margin="10 0 0 0">Example:  connection.GetSchema("DataTypes")</TextBlock>
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="Association Schema">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Label Content="Custom Query"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <TextBox Grid.Row="1"
                             Text="{Binding AssociationSchemaSql}"
                             TextWrapping="Wrap" />
                    <Label Content="Expected Results Format"
                           Grid.Row="2"
                           Grid.ColumnSpan="3"
                           Style="{StaticResource PanelHeaderBackground}"
                           Margin="0" />
                    <DataGrid Grid.Row="3"
                              ItemsSource="{Binding AssociationSchemaInfo}"
                              AutoGenerateColumns="False"
                              CanUserReorderColumns="False"
                              CanUserResizeColumns="False"
                              CanUserResizeRows="False"
                              CanUserSortColumns="False"
                              Focusable="False"
                              IsReadOnly="True">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Column Name"
                                                Binding="{Binding ColumnName}" />
                            <DataGridTextColumn Header="Type"
                                                Binding="{Binding Type}" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
        </TabControl>
        <StackPanel Orientation="Horizontal"
                    Grid.Row="1"
                    HorizontalAlignment="Right">
            <Button Content="Ok"
                    Command="{Binding OkCommand}" />
            <Button Content="Cancel"
                    Command="{Binding CloseCommand}" />
        </StackPanel>
    </Grid>
</UserControl>
